import { injectable } from 'inversify';
import { EditorMode, EditorState, IEditorService } from '../types';

@injectable()
export class EditorService implements IEditorService {
    private state: EditorState = {
        mode: '2d'
    };

    private listeners: ((state: EditorState) => void)[] = [];

    subscribe(listener: (state: EditorState) => void) {
        this.listeners.push(listener);
        return () => {
            this.listeners = this.listeners.filter(l => l !== listener);
        };
    }

    private notifyListeners() {
        this.listeners.forEach(listener => listener(this.state));
    }

    getMode(): EditorMode {
        return this.state.mode;
    }

    setMode(mode: EditorMode): void {
        this.state.mode = mode;
        this.notifyListeners();
    }

    getState(): EditorState {
        return this.state;
    }
} 